#ifndef VIEWER_H
#define VIEWER_H

#include "MapDrawer.h"
#include "Tracking.h"
#include "System.h"
#include "Settings.h"

#include <mutex>

namespace msf
{
class Tracking;
class MapDrawer;
class System;
class Settings;

class Viewer
{
public:
      EIGEN_MAKE_ALIGNED_OPERATOR_NEW
      Viewer(System* pSystem, MapDrawer *pMapDrawer, Tracking *pTracking, Settings* settings);

      void newParameterLoader(Settings* settings);

      // 主线程函数。绘制关键位姿帧和当前位姿帧。根据fps刷新绘图。使用Pangolin。
      void Run();

      void RequestFinish();

      void RequestStop();

      bool isFinished();

      bool isStopped();

      bool isStepByStep();

      void Release();

      bool both;

private:

      bool Stop();

      System* mpSystem;
      MapDrawer* mpMapDrawer;
      Tracking* mpTracker;

      // 1/fps in ms
      double mT;
      float mImageWidth, mImageHeight;
      float mImageViewerScale;

      float mViewpointX, mViewpointY, mViewpointZ, mViewpointF;

      bool CheckFinish();
      void SetFinish();
      bool mbFinishRequested;
      bool mbFinished;
      std::mutex mMutexFinish;

      bool mbStopped;
      bool mbStopRequested;
      std::mutex mMutexStop;

      bool mbStopTrack;

};
} // namespace msf

#endif // VIEWER_H